#include <bits/stdc++.h>
using namespace std;
int n, r, c, d, x, y, xx, yy, s, t;
inline int id(int x, int y) {
    return (x - 1) * c + y;
}
bool arr[1010];
int len[1010][1010];
int dis[1010];
bool vis[1010];
int main() {
    freopen("stamp.in", "r", stdin);
    freopen("stamp.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> r >> c >> d >> x >> y >> xx >> yy;
    n = r * c;
    for (int i = 1; i <= r; i++) {
        string str;
        cin >> str;
        for (int j = 1; j <= c; j++) {
            arr[id(i, j)] = (str[j-1] == '#');
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            len[i][j] = -1;
        }
    }
    for (int i = 1; i <= r; i++) {
        for (int j = 1; j <= c; j++) {
            for (int k = 1; k <= r; k++) {
                for (int l = 1; l <= c; l++) {
                    int u = id(i, j);
                    int v = id(k, l);
                    int dx = abs(i - k);
                    int dy = abs(j - l);
                    if (dx <= d && dy <= d && (dx < d || dy < d)) {
                        len[u][v] = 1;
                    }
                }
            }
        }
    }
    for (int i = 1; i <= r; i++) {
        for (int j = 1; j <= c; j++) {
            int u = id(i, j);
            len[u][u] = 0;
            if (!arr[u]) {
                if (i != 1) len[u][id(i - 1, j)] = 0;
                if (i != r) len[u][id(i + 1, j)] = 0;
                if (j != 1) len[u][id(i, j - 1)] = 0;
                if (j != c) len[u][id(i, j + 1)] = 0;
            }
        }
    }
    s = id(x, y);
    t = id(xx, yy);
    for (int i = 1; i <= n; i++) {
        dis[i] = -1;
    }
    dis[s] = 0;
    while (true) {
        int pos = -1;
        for (int i = 1; i <= n; i++) {
            if (!vis[i] && dis[i] != -1) {
                if (pos == -1 || dis[i] < dis[pos]) {
                    pos = i;
                }
            }
        }
        if (pos == -1) break;
        vis[pos] = true;
        for (int i = 1; i <= n; i++) {
            if (!vis[i] && len[pos][i] != -1) {
                int tmp = dis[pos] + len[pos][i];
                if (dis[i] == -1 || dis[i] > tmp) {
                    dis[i] = tmp;
                }
            }
        }
    }
    cout << dis[t] << endl;
    return 0;
}